package com.zr.action;

import java.io.PrintWriter;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.fileupload.servlet.ServletRequestContext;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.junit.runner.Request;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.zr.datamodel.PointPriceDM;
import com.zr.service.PointPriceService;

import net.sf.json.JSONObject;
import ognl.JJTOgnlParserState;
@Controller
@Scope(value="prototype")
public class PointPriceAction  implements Action,ServletResponseAware,ServletRequestAware {
	@Resource
	private PointPriceService pointPriceService;
	private HttpServletRequest request;     //HttpServletRequest�ͱ���request����  
	private HttpServletResponse response; 
	public JSONObject findPointPriceMsg(int page, int rows) {
			// TODO Auto-generated method stub
			return null;
	}
	@Override
	public void setServletRequest(HttpServletRequest request) {
		// TODO Auto-generated method stub
		this.request=request;
	}

	@Override
	public void setServletResponse(HttpServletResponse response) {
		// TODO Auto-generated method stub
		this.response=response;
	}
	/**
	 * 增加配送点价格信息
	 * @return
	 * @throws Exception
	 */
	public void addPointPrice() throws Exception{
		String startName=request.getParameter("startName");
		String pointName=request.getParameter("pointName");
		int firstPrice=Integer.parseInt(request.getParameter("firstPrice"));
		int nextPrice=Integer.parseInt(request.getParameter("nextPrice"));
		int firstcPrice=Integer.parseInt(request.getParameter("firstcPrice")); 
		int nextcPrice=Integer.parseInt(request.getParameter("nextcPrice"));
		response.setCharacterEncoding("utf8");
		pointPriceService.addPointPrice(startName, pointName, firstPrice, nextPrice, firstcPrice, nextcPrice);
	}
	/**
	 * 查询所有配送点价格
	 * @return 
	 * @throws Exception
	 */
	public void selectPointPrice() throws Exception{
		int page=Integer.parseInt(request.getParameter("page"));
		int rows=Integer.parseInt(request.getParameter("rows"));
		JSONObject obj=pointPriceService.findPointPriceMsg(page, rows);
		response.setCharacterEncoding("utf8");
		response.getWriter().write(obj.toString());
	}
	/**
	 * 根据配送点名称查询配送点价格信息
	 * @throws Exception
	 */
	public void selectPointPriceByPointName() throws Exception{
		String pointName=request.getParameter("pointName");
		int page=Integer.parseInt(request.getParameter("page"));
		int rows=Integer.parseInt(request.getParameter("rows"));
		JSONObject obj=pointPriceService.selectPointPriceByPointName(pointName, page, rows);
		response.setCharacterEncoding("utf8");
		response.getWriter().write(obj.toString());
	}
	/**
	 * 删除选中配送点价格信息
	 * @throws Exception
	 */
	public void delPointPrice() throws Exception {
		String strs[]= request.getParameterValues("ids[]");
		pointPriceService.delPointPrice(strs);
	}
	/**
	 * 修改选中配送点价格信息
	 * @throws Exception
	 */
	public void updatePointPrice() throws Exception {
		int id=Integer.parseInt(request.getParameter("id"));
		String startName=request.getParameter("startName");
		System.out.println(startName);
		String pointName=request.getParameter("pointName");
		int firstPrice=Integer.parseInt(request.getParameter("firstPrice"));
		int nextPrice=Integer.parseInt(request.getParameter("nextPrice"));
		int firstcPrice=Integer.parseInt(request.getParameter("firstcPrice")); 
		int nextcPrice=Integer.parseInt(request.getParameter("nextcPrice"));
		PointPriceDM pointPriceDM=new PointPriceDM();
		pointPriceDM.setId(id);
		pointPriceDM.setStartName(startName);
		pointPriceDM.setPointName(pointName);
		pointPriceDM.setFirstPrice(firstPrice);
		pointPriceDM.setFirstcPrice(firstcPrice);
		pointPriceDM.setNextPrice(nextPrice);
		pointPriceDM.setNextcPrice(nextcPrice);
		pointPriceService.updatePointPrice(pointPriceDM);
	}
	@Override
	public String execute() throws Exception {
		// TODO Auto-generated method stub
		return null;
	}
	
}
